<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <a-card :bordered="false" title="提现基础设置" style="margin-bottom: 30px">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="8" :lg="7" :md="8" :sm="24">
              <a-form-item label="提现次数限制：">
                <a-input-number :min="0" style="width: 80%" placeholder="请输入" v-model="WithdrawalNum"></a-input-number> 次/天
              </a-form-item>
            </a-col>
            <a-col :xl="8" :lg="7" :md="8" :sm="24">
              <a-form-item label="推广人员提现手续费：">
                <a-input-number :min="0" style="width: 80%" placeholder="请输入" v-model="WithdrawalTgCommission"></a-input-number> %
              </a-form-item>
            </a-col>
            <a-col :xl="8" :lg="7" :md="8" :sm="24">
              <a-form-item label="非推广人员提现手续费：">
                <a-input-number :min="0" style="width: 80%" placeholder="请输入" v-model="WithdrawalUnTgCommission"></a-input-number> %
              </a-form-item>
            </a-col>
            <a-col :xl="8" :lg="7" :md="8" :sm="24">
              <a-form-item label="提现提示语：">
                <a-textarea help="1324213" :rows="4" :min="0" style="width: 100%" placeholder="请输入" v-model="WithdrawalPrompt"></a-textarea>
              </a-form-item>
            </a-col>
            <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="submitForm" icon="search">确认修改</a-button>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>

    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">添加提现套餐</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">


           <template slot='type' slot-scope='text, record'>
          <div v-if="record.type == 1" style='color: #169bd5'>银行卡</div>
          <div v-if="record.type == 2" style='color: #000000'>支付宝</div>
        </template>



        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <withdrawal-settings-modal ref="modalForm" @ok="modalFormOk"></withdrawal-settings-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import WithdrawalSettingsModal from './modules/WithdrawalSettingsModal'
  import { httpAction, getAction } from '@/api/manage'

  export default {
    name: 'WithdrawalSettingsList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      WithdrawalSettingsModal
    },
    data () {
      return {
        description: '提现设置管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'创建日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'提现金额(人民币)',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title:'提现方式',
            align:"center",
            dataIndex: 'type',
            scopedSlots: { customRender: 'type' }
          },
          {
            title:'兑换钻石',
            align:"center",
            dataIndex: 'exchangeDiamond'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/system/withdrawalSettings/list",
          delete: "/system/withdrawalSettings/delete",
          deleteBatch: "/system/withdrawalSettings/deleteBatch",
          exportXlsUrl: "/system/withdrawalSettings/exportXls",
          importExcelUrl: "system/withdrawalSettings/importExcel",

        },
        dictOptions:{},
        superFieldList:[],

        WithdrawalNum:"",
        WithdrawalTgCommission:"",
        WithdrawalUnTgCommission:"",
        WithdrawalPrompt:"",
      }
    },
    created() {
    this.getSuperFieldList();
    this.getSystemConfigMap();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'amount',text:'提现金额(人民币)',dictCode:''})
        fieldList.push({type:'string',value:'exchangeDiamond',text:'兑换钻石',dictCode:''})
        this.superFieldList = fieldList
      },

      //获取回显数据
      getSystemConfigMap(){
        getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
          if(res.success){
            this.WithdrawalNum=res.result.WithdrawalNum;
            this.WithdrawalTgCommission=res.result.WithdrawalTgCommission;
            this.WithdrawalUnTgCommission=res.result.WithdrawalUnTgCommission;
            this.WithdrawalPrompt=res.result.WithdrawalPrompt;
          }
        })
      },
      //保存数据
      submitForm () {
        const that = this;
        if(!this.WithdrawalNum){
          this.$message.warning("请填写提现次数限制");
          return;
        }
        if(!this.WithdrawalTgCommission){
          this.$message.warning("请填写推广人员提现手续费");
          return;
        }
        if(!this.WithdrawalUnTgCommission){
          this.$message.warning("请填写非推广人员提现手续费");
          return;
        }
        if(!this.WithdrawalPrompt){
          this.$message.warning("请填写提现提示语");
          return;
        }
        // 触发表单验证
        let httpurl = '/system/systemConfig/saveOrUpdate';
        let method = 'post';
        let dataList=[];
        let obj={};
        obj.code="WithdrawalNum";
        obj.value=this.WithdrawalNum;
        obj.title="提现次数限制";
        dataList.push(obj);
        obj={};
        obj.code="WithdrawalTgCommission";
        obj.value=this.WithdrawalTgCommission;
        obj.title="推广人员提现手续费";
        dataList.push(obj);
        obj={};
        obj.code="WithdrawalUnTgCommission";
        obj.value=this.WithdrawalUnTgCommission;
        obj.title="非推广人员提现手续费";
        dataList.push(obj);
        obj={};
        obj.code="WithdrawalPrompt";
        obj.value=this.WithdrawalPrompt;
        obj.title="提现提示语";
        dataList.push(obj);


        httpAction(httpurl,dataList,method).then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            that.$emit('ok');
          }else{
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.confirmLoading = false;
        })

      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>